#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;
using i64 = int64_t;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> scores(n + 1);
  for (int i = 1; i <= n; i ++) cin >> scores[i];
  vector<vector<i64>> dp(n + 2, vector<i64>(n + 2, 1));
  vector<vector<int>> opt(n + 2, vector<int>(n + 2));
  for (int l = n; l >= 1; l--) {
    dp[l][l] = scores[l];
    for (int r = l + 1; r <= n; r++) {
      dp[l][r] = 0;
      for (int k = l; k <= r; k++) {
        i64 v = dp[l][k - 1] * dp[k + 1][r] + scores[k];
        if (v > dp[l][r]) {
          dp[l][r] = v;
          opt[l][r] = k;
        }
      }
    }
  }
  cout << dp[1][n] << endl;
  auto output = [&](auto &self, int l, int r) {
    if (l > r) return;
    if (l == r) {
      cout << l << ' ';
      return;
    }
    cout << opt[l][r] << ' ';
    self(self, l, opt[l][r] - 1);
    self(self, opt[l][r] + 1, r);
  };
  output(output, 1, n);
  cout << endl;
}